package streamingStudy.testStreaming

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

object NetcatWordCount {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("streamingWC...")
    val streamingContext = new StreamingContext(sparkConf, Seconds(3))

    val lineStreams = streamingContext.socketTextStream("192.168.200.201", 9999)
    val wordStreams = lineStreams.flatMap(_.split(" "))
    val wordAndOneStrteams = wordStreams.map((_, 1))
    val wordAndCountStreams = wordAndOneStrteams.reduceByKey(_ + _)

    wordAndCountStreams.print()

    streamingContext.start()
    streamingContext.awaitTermination()
  }

}
